package gui;

import logik.ATM;
import logik.BalanceInquiry;
import logik.CashDispenser;
import logik.Deposit;
import logik.DepositSlot;
import logik.InterestRate;
import logik.Transaction;
import logik.Withdrawal;
import data.BankDatabase;

public class AccountMenu extends UserMenu{

	/**
	 * Represents all variables
	 */
	// private boolean userAuthenticated; // whether user is authenticated
	private int currentAccountNumber; // current user's account number
	private Screen screen; // ATM's screen
	private CashDispenser cashDispenser; // ATM's cash dispenser
	private DepositSlot depositSlot; // ATM's deposit slot
	private BankDatabase bankDatabase; // account information database
	private String accountType = null;
	private UserMenu usermenu;
	private Deposit deposit;
//	public boolean userAuthenticated;
	private boolean envelopeReceived;
	private ATM atm;
	private final int maxAcc = 3;
	
	/*** Constants corresponding to main menu options	 */
	private static final int BALANCE_INQUIRY = 1;
	/*** hi*/
	private static final int WITHDRAWAL = 2;
	/*** */
	private static final int DEPOSIT = 3;
	/*** */
	private static final int RATE = 4;
	/*** */
	private static final int EXIT = 5;

	/**
	 * no-argument ATM constructor initializes instance variables
	 */
	
	//constructor stuff 
	public AccountMenu (Screen screen, int currentAccountNumber, CashDispenser cashDispenser,
			DepositSlot depositSlot, BankDatabase bankDatabase, UserMenu usermenu, boolean userAuthenticated,
			String accountType, ATM atm, int maxAcc, Deposit deposit) {
		super(currentAccountNumber, userAuthenticated, bankDatabase, screen, 
				accountType, atm, maxAcc); 
			this.screen = screen;
			this.currentAccountNumber = currentAccountNumber;
			this.cashDispenser = cashDispenser;
			this.depositSlot = depositSlot;
			this.bankDatabase = bankDatabase;
			this.usermenu = usermenu;
			this.userAuthenticated = userAuthenticated;
			this.accountType = accountType;
			this.deposit = deposit;
		//	this.chooseAccount = chooseAccount;
		//userAuthenticated = false; // user is not authenticated to start
		//currentAccountNumber = 0; // no current account number to start
		// cashDispenser = new CashDispenser(); // create cash dispenser
	//	depositSlot = new DepositSlot(); // create deposit slot
	//	bankDatabase = new BankDatabase(keypad); // create acct info database
	//	usermenu = new UserMenu(currentAccountNumber, false, bankDatabase, 
	//			screen, keypad, accountType, null, currentAccountNumber, null);
	
	} // end no-argument ATM constructor
	
	public final void performTransactions() {
		//screen = new Screen();
		// System.out.println(screen + "AccountMenu passed");
		// local variable to store transaction currently being processed
		Transaction currentTransaction = null;

		boolean userExited = false; // user has not chosen to exit

		// loop while user has not chosen option to exit system
		while (!userExited) {
			// show main menu and get user selection
			int mainMenuSelection = displayMainMenu();

			// decide how to proceed based on user's menu selection
			switch (mainMenuSelection) {
			// user chose to perform one of four transaction types
			case BALANCE_INQUIRY: 
			case WITHDRAWAL: 
			case DEPOSIT:
			case RATE:

				// initialize as new object of chosen type
				currentTransaction = 
				createTransaction(mainMenuSelection);

				currentTransaction.execute(); // execute transaction
				break; 
			default: // user did not enter an integer from 1-4
//				screen.displayMessageLine(
//						"\nYou did not enter a valid selection. Try again.");
				break;

			case EXIT:
//				screen.displayMessageLine("\nExiting the system...");
//				userExited = true; // this ATM session should end
//				usermenu = new UserMenu(mainMenuSelection, userExited, bankDatabase, screen, keypad, accountType, atm, mainMenuSelection);
//				usermenu.userAuthenticated = false;

			} // end switch
		} // end while
	} // end method performTransactions

	/**
	 * @param type
	 * @return // return object of specified Transaction subclass
	 */
	private Transaction createTransaction(int type) {
		Transaction temp = null; // temporary Transaction variable

		// determine which type of Transaction to create     
		switch (type) {
		case BALANCE_INQUIRY: // create new BalanceInquiry transaction
			temp = new BalanceInquiry(
					currentAccountNumber, screen, bankDatabase);
			break;
		case WITHDRAWAL: // create new Withdrawal transaction
			temp = new Withdrawal(currentAccountNumber, screen, 
					bankDatabase, cashDispenser);
			break; 
		case DEPOSIT: // create new Deposit transaction
			temp = new Deposit(currentAccountNumber, screen, 
					bankDatabase, depositSlot);
			break;
		case RATE:
			temp = new InterestRate(currentAccountNumber, screen, 
					bankDatabase, accountType);

			break;
		} // end switch
		return temp; // return the newly created object
	} // end method createTransaction
} // end class ATM